<?php

/**
 * This is the model class for table "datosusuarios".
 *
 * The followings are the available columns in table 'datosusuarios':
 * @property integer $idDatosUsuarios
 * @property string $usuario
 * @property string $password
 * @property string $telefono
 * @property string $mail
 * @property integer $Usuarios_idUsuarios
 *
 * The followings are the available model relations:
 * @property Usuarios $usuariosIdUsuarios
 */
class Datosusuarios extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Datosusuarios the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'datosusuarios';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('usuario, password, telefono, mail, Usuarios_idUsuarios', 'required'),
			array('Usuarios_idUsuarios', 'numerical', 'integerOnly'=>true),
			array('usuario, password, telefono, mail', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idDatosUsuarios, usuario, password, telefono, mail, Usuarios_idUsuarios', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'usuariosIdUsuarios' => array(self::BELONGS_TO, 'Usuarios', 'Usuarios_idUsuarios'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idDatosUsuarios' => 'Id Datos Usuarios',
			'usuario' => 'Usuario',
			'password' => 'Password',
			'telefono' => 'Telefono',
			'mail' => 'Mail',
			'Usuarios_idUsuarios' => 'Usuarios Id Usuarios',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idDatosUsuarios',$this->idDatosUsuarios);
		$criteria->compare('usuario',$this->usuario,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('telefono',$this->telefono,true);
		$criteria->compare('mail',$this->mail,true);
		$criteria->compare('Usuarios_idUsuarios',$this->Usuarios_idUsuarios);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	
		
	public function validatePassword($password)
	{
		return $this->password==$this->password;
	}

	/**
	 * Generates the password hash.
	 * @param string password
	 * @param string salt
	 * @return string hash
	 */
	public function hashPassword($password,$salt)
	{
		return md5($salt.$password);
	}

	/**
	 * Generates a salt that can be used to generate a password hash.
	 * @return string the salt
	 */
	public function generateSalt()
	{
		return uniqid('',true);
	}
}